
*******************************************************************************
*BRING IN SCF DATA WITH DIFFERENT RANKS
*******************************************************************************

*wealth vars by scenario (for SCF capitalization replication of SZ fig IVB)
* rank1. total raw scf wealth
* rank2. fix + equ + bus, raw scf
* rank3. fix + equ + bus, scf capitalized
* rank4. fix + equ + bus, scf capitalized (but no kg capitalization on equities)
* rank5. fix + equ + bus, Financial Accounts capitalized (but no kg capitalization on equities) 
* note: x4 is needed for ranking without kg, but x3 is the value that is used (which includes kg in the capitalization)

*g hweal_rank1 = hweal_rawscf
*g hweal_rank2 = taxbond_rawscf + ccorw_rawscf + busw_rawscf + currency_rawscf + nonmort_rawscf + muni_rawscf
*g hweal_rank3 = taxbond_iscf + ccorw_iscf  + busw_iscf  + currency_rawscf + nonmort_rawscf + muni_iscf
*g hweal_rank4 = taxbond_iscf + ccorw_0kg_iscf + busw_iscf  + currency_rawscf + nonmort_rawscf + muni_iscf
*g hweal_rank5 = taxbond + ccorw_0kg + busw  + currency_rawscf + nonmort_rawscf + muni_iscf

********************************************************************************
*5 ranks for graphing, appending by year
********************************************************************************

forv r=1/7{
	import delim "$outdir/wealth_stats_scf/wealth_sz_scf_rank`r'_1989.csv", clear
	capture drop year
	gen year = 1989
	tempfile temp
	save `temp', replace
	foreach yr in "1992" "1995" "1998" "2001" "2004" "2007" "2010" "2013" "2016" {
		import delim "$outdir/wealth_stats_scf/wealth_sz_scf_rank`r'_`yr'.csv", clear
		capture drop year
		gen year = `yr'
		append using `temp'
		save `temp', replace
	}
	order group year 
	save "$outdir/wealth_stats_scf/wealth_sz_scf_rank`r'", replace

}
/*
********************************************************************************
********************************************************************************
* Graph With Single Ranking, Ranked by RAW SCF Wealth (excluding housing and pensions as in SZ FIG 4B);
********************************************************************************
********************************************************************************

#delimit;

use "$outdir/wealth_stats_scf/wealth_sz_scf_rank2", clear;

	twoway (scatter hweal_rank2_frac year if w2_group == 2, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l)) 
	(scatter hweal_rank3_frac year if w2_group == 2, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash))
	(scatter hweal_rank2_frac year if w2_group == 3, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l))
	(scatter hweal_rank3_frac year if w2_group == 3, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash))
	(scatter hweal_rank2_frac year if w2_group == 4, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l))
	(scatter hweal_rank3_frac year if w2_group == 4, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash))
	,
	$graphconfig ytitle("Share of Household Wealth (%)" "(Excluding Housing and Pensions)") xtitle("") 
		legend(label(1 "SCF Top 10%") 
			   label(2 "SCF Capitalized Top 10%") 
			   label(3 "SCF Top 1%") 
			   label(4 "SCF Capitalized Top 1%") 
			   label(5 "SCF Top 0.1%") 
			   label(6 "SCF Capitalized Top 0.1%")
			   order(1 2 3 4 5 6) row(3) region(lc(white))) 
		ysc(titlegap(2))  ylab(0(.2)1)
		xlab(1989(3)2016)	
		/* title("Ranking Based on SCF Wealth") */
	;
	
graph export "$figdir/sz_scf_fig4b_rank_rawscf.pdf", replace;

***********
* taxbond using non-hou non-pen raw SCF wealth (ie rank2 wealth)
***********
#delimit;

use "$outdir/wealth_stats_scf/wealth_sz_scf_rank2", clear;

	twoway (scatter taxbond_rawscf_frac year if w2_group == 2, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l)) 
	(scatter taxbond_iscf_frac year if w2_group == 2, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash))
	(scatter taxbond_rawscf_frac year if w2_group == 3, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l))
	(scatter taxbond_iscf_frac year if w2_group == 3, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash))
	(scatter taxbond_rawscf_frac year if w2_group == 4, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l))
	(scatter taxbond_iscf_frac year if w2_group == 4, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash))
	,
	$graphconfig ytitle("Share of Fixed Income Wealth (%)") xtitle("") 
		legend(label(1 "SCF Top 10%") 
			   label(2 "SCF Capitalized Top 10%") 
			   label(3 "SCF Top 1%") 
			   label(4 "SCF Capitalized Top 1%") 
			   label(5 "SCF Top 0.1%") 
			   label(6 "SCF Capitalized Top 0.1%")
			   order(1 2 3 4 5 6) row(3) region(lc(white))) 
		ysc(titlegap(2))  ylab(0(.2)1)
		xlab(1989(3)2016)	
		/* title("Ranking Based on SCF Wealth") */
	;
	
graph export "$figdir/sz_scf_fig4b_rank_rawscf_taxbond.pdf", replace;

***********
* non c corp biz using non-hou non-pen raw SCF wealth (ie rank2 wealth)
***********
#delimit;

use "$outdir/wealth_stats_scf/wealth_sz_scf_rank2", clear;

	twoway (scatter busw_rawscf_frac year if w2_group == 2, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l)) 
	(scatter busw_iscf_frac year if w2_group == 2, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash))
	(scatter busw_rawscf_frac year if w2_group == 3, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l))
	(scatter busw_iscf_frac year if w2_group == 3, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash))
	(scatter busw_rawscf_frac year if w2_group == 4, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l))
	(scatter busw_iscf_frac year if w2_group == 4, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash))
	,
	$graphconfig ytitle("Share of Non C-corp Business Wealth (%)") xtitle("") 
		legend(label(1 "SCF Top 10%") 
			   label(2 "SCF Capitalized Top 10%") 
			   label(3 "SCF Top 1%") 
			   label(4 "SCF Capitalized Top 1%") 
			   label(5 "SCF Top 0.1%") 
			   label(6 "SCF Capitalized Top 0.1%")
			   order(1 2 3 4 5 6) row(3) region(lc(white))) 
		ysc(titlegap(2))  ylab(0(.2)1)
		xlab(1989(3)2016)	
		/* title("Ranking Based on SCF Wealth") */
	;
	
graph export "$figdir/sz_scf_fig4b_rank_rawscf_busw.pdf", replace;


***********
* c corp using non-hou non-pen raw SCF wealth (ie rank2 wealth)
***********
#delimit;

use "$outdir/wealth_stats_scf/wealth_sz_scf_rank2", clear;

	twoway (scatter ccorw_rawscf_frac year if w2_group == 2, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l)) 
	(scatter ccorw_iscf_frac year if w2_group == 2, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash))
	(scatter ccorw_rawscf_frac year if w2_group == 3, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l))
	(scatter ccorw_iscf_frac year if w2_group == 3, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash))
	(scatter ccorw_rawscf_frac year if w2_group == 4, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l))
	(scatter ccorw_iscf_frac year if w2_group == 4, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash))
	,
	$graphconfig ytitle("Share of C-corp Wealth (%)") xtitle("") 
		legend(label(1 "SCF Top 10%") 
			   label(2 "SCF Capitalized Top 10%") 
			   label(3 "SCF Top 1%") 
			   label(4 "SCF Capitalized Top 1%") 
			   label(5 "SCF Top 0.1%") 
			   label(6 "SCF Capitalized Top 0.1%")
			   order(1 2 3 4 5 6) row(3) region(lc(white))) 
		ysc(titlegap(2))  ylab(0(.2)1)
		xlab(1989(3)2016)	
		/* title("Ranking Based on SCF Wealth") */
	;
	
graph export "$figdir/sz_scf_fig4b_rank_rawscf_ccorp.pdf", replace;


********************************************************************************
********************************************************************************
* Graph With Single Ranking, Ranked by  Capitalized SCF Wealth(excluding housing and pensions as in SZ FIG 4B);
********************************************************************************
********************************************************************************
#delimit;

use "$outdir/wealth_stats_scf/wealth_sz_scf_rank4", clear;
replace year = year - 1;

	twoway (scatter hweal_rank2_frac year if w4_group == 2, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l)) 
	(scatter hweal_rank3_frac year if w4_group == 2, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash))
	(scatter hweal_rank2_frac year if w4_group == 3, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l))
	(scatter hweal_rank3_frac year if w4_group == 3, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash))
	(scatter hweal_rank2_frac year if w4_group == 4, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l))
	(scatter hweal_rank3_frac year if w4_group == 4, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash))
	,
	$graphconfig ytitle("Share of Household Wealth (%)" "(Excluding Housing and Pensions)") xtitle("") 
		legend(label(1 "SCF Top 10%") 
			   label(2 "SCF Capitalized Top 10%") 
			   label(3 "SCF Top 1%") 
			   label(4 "SCF Capitalized Top 1%") 
			   label(5 "SCF Top 0.1%") 
			   label(6 "SCF Capitalized Top 0.1%")
			   order(1 2 3 4 5 6) row(3) region(lc(white))) 
		ysc(titlegap(2))  ylab(0(.2)1)
		xlab(1988(3)2016)
		/* title("Ranking Based on Capitalized SCF Wealth") */
	;
	
graph export "$figdir/sz_scf_fig4b_rank_iscf.pdf", replace;

***********
* taxbond using non-hou non-pen capitalized SCF wealth 
***********
#delimit;

use "$outdir/wealth_stats_scf/wealth_sz_scf_rank4", clear;

	twoway (scatter taxbond_rawscf_frac year if w4_group == 2, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l)) 
	(scatter taxbond_iscf_frac year if w4_group == 2, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash))
	(scatter taxbond_rawscf_frac year if w4_group == 3, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l))
	(scatter taxbond_iscf_frac year if w4_group == 3, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash))
	(scatter taxbond_rawscf_frac year if w4_group == 4, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l))
	(scatter taxbond_iscf_frac year if w4_group == 4, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash))
	,
	$graphconfig ytitle("Share of Fixed Income Wealth (%)") xtitle("") 
		legend(label(1 "SCF Top 10%") 
			   label(2 "SCF Capitalized Top 10%") 
			   label(3 "SCF Top 1%") 
			   label(4 "SCF Capitalized Top 1%") 
			   label(5 "SCF Top 0.1%") 
			   label(6 "SCF Capitalized Top 0.1%")
			   order(1 2 3 4 5 6) row(3) region(lc(white))) 
		ysc(titlegap(2))  ylab(0(.2)1)
		xlab(1989(3)2016)	
	;
	
graph export "$figdir/sz_scf_fig4b_rank_iscf_taxbond.pdf", replace;

***********
* non c corp biz using non-hou non-pen capitalized SCF wealth 
***********
#delimit;

use "$outdir/wealth_stats_scf/wealth_sz_scf_rank4", clear;

	twoway (scatter busw_rawscf_frac year if w4_group == 2, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l)) 
	(scatter busw_iscf_frac year if w4_group == 2, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash))
	(scatter busw_rawscf_frac year if w4_group == 3, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l))
	(scatter busw_iscf_frac year if w4_group == 3, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash))
	(scatter busw_rawscf_frac year if w4_group == 4, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l))
	(scatter busw_iscf_frac year if w4_group == 4, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash))
	,
	$graphconfig ytitle("Share of Non C-corp Business Wealth (%)") xtitle("") 
		legend(label(1 "SCF Top 10%") 
			   label(2 "SCF Capitalized Top 10%") 
			   label(3 "SCF Top 1%") 
			   label(4 "SCF Capitalized Top 1%") 
			   label(5 "SCF Top 0.1%") 
			   label(6 "SCF Capitalized Top 0.1%")
			   order(1 2 3 4 5 6) row(3) region(lc(white))) 
		ysc(titlegap(2))  ylab(0(.2)1)
		xlab(1989(3)2016)	
	;
	
graph export "$figdir/sz_scf_fig4b_rank_iscf_busw.pdf", replace;


***********
* c corp using non-hou non-pen capitalized SCF wealth 
***********
#delimit;

use "$outdir/wealth_stats_scf/wealth_sz_scf_rank4", clear;

	twoway (scatter ccorw_rawscf_frac year if w4_group == 2, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l)) 
	(scatter ccorw_iscf_frac year if w4_group == 2, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash))
	(scatter ccorw_rawscf_frac year if w4_group == 3, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l))
	(scatter ccorw_iscf_frac year if w4_group == 3, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash))
	(scatter ccorw_rawscf_frac year if w4_group == 4, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l))
	(scatter ccorw_iscf_frac year if w4_group == 4, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash))
	,
	$graphconfig ytitle("Share of C-corp Wealth (%)") xtitle("") 
		legend(label(1 "SCF Top 10%") 
			   label(2 "SCF Capitalized Top 10%") 
			   label(3 "SCF Top 1%") 
			   label(4 "SCF Capitalized Top 1%") 
			   label(5 "SCF Top 0.1%") 
			   label(6 "SCF Capitalized Top 0.1%")
			   order(1 2 3 4 5 6) row(3) region(lc(white))) 
		ysc(titlegap(2))  ylab(0(.2)1)
		xlab(1989(3)2016)	
	;
	
graph export "$figdir/sz_scf_fig4b_rank_iscf_ccorp.pdf", replace;
*/
********************************************************************************
********************************************************************************
* Graph With Re-Ranking, Wealth (excluding housing and pensions as in SZ FIG 4B);
********************************************************************************
********************************************************************************


use "$outdir/wealth_stats_scf/wealth_sz_scf_rank2", clear

local sumlist_new = "n hweal_rank1 hweal_rank2 hweal_rank3 hweal_rank4 taxbond_rawscf taxbond_iscf muni_rawscf muni_iscf currency_rawscf nonmort_rawscf ccorw_rawscf ccorw_iscf ccorw_0kg_iscf busw_rawscf busw_iscf"

foreach var in `sumlist_new' w2_group *_frac{
	rename `var' `var'_rank2
}

drop group
rename w2_group group

tempfile super_temp
save `super_temp'

clear
*Use capitalized rank excluding cap gains
use "$outdir/wealth_stats_scf/wealth_sz_scf_rank4", clear
replace year = year - 1
drop group
rename w4_group group

merge 1:1 year group using `super_temp', nogen

*****************************************************
*** MAIN GRAPH with re-ranking
*****************************************************
	twoway (scatter hweal_rank2_frac_rank2 year if group == 2, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l)) ///
	(scatter hweal_rank3_frac year if group == 2, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash)) ///
	(scatter hweal_rank2_frac_rank2 year if group == 3, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l)) ///
	(scatter hweal_rank3_frac year if group == 3, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash)) ///
	(scatter hweal_rank2_frac_rank2 year if group == 4, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l)) ///
	(scatter hweal_rank3_frac year if group == 4, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash)) ///
	, ///
	$graphconfig ytitle("Share of Household Wealth (%)" "(Excluding Housing and Pensions)") xtitle("") ///
		legend(label(1 "SCF Top 10%")  ///
			   label(2 "SCF Capitalized Top 10%") ///
			   label(3 "SCF Top 1%") ///
			   label(4 "SCF Capitalized Top 1%") ///
			   label(5 "SCF Top 0.1%") ///
			   label(6 "SCF Capitalized Top 0.1%") ///
			   order(1 2 3 4 5 6) row(3) region(lc(white))) ///
		ysc(titlegap(2))  ylab(0(.2)1) ///
		xlab(1988(3)2012)

graph export "$figdir/sz_scf_fig4b_rerank.pdf", replace

*****************************************************
*** taxbond with re-ranking
*****************************************************
	twoway (scatter taxbond_rawscf_frac_rank2 year if group == 2, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l)) ///
	(scatter taxbond_iscf_frac year if group == 2, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash)) ///
	(scatter taxbond_rawscf_frac_rank2 year if group == 3, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l)) ///
	(scatter taxbond_iscf_frac year if group == 3, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash)) ///
	(scatter taxbond_rawscf_frac_rank2 year if group == 4, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l)) ///
	(scatter taxbond_iscf_frac year if group == 4, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash)) ///
	, ///
	$graphconfig ytitle("Share of Fixed Income Wealth (%)") xtitle("") ///
		legend(label(1 "SCF Top 10%")  ///
			   label(2 "SCF Capitalized Top 10%") ///
			   label(3 "SCF Top 1%") ///
			   label(4 "SCF Capitalized Top 1%") ///
			   label(5 "SCF Top 0.1%") ///
			   label(6 "SCF Capitalized Top 0.1%") ///
			   order(1 2 3 4 5 6) row(3) region(lc(white))) ///
		ysc(titlegap(2))  ylab(0(.2)1) ///
		xlab(1988(3)2012)

graph export "$figdir/sz_scf_fig4b_rerank_taxbond.pdf", replace


*****************************************************
*** non c corp biz  with re-ranking
*****************************************************
	twoway (scatter busw_rawscf_frac_rank2 year if group == 2, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l)) ///
	(scatter busw_iscf_frac year if group == 2, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash)) ///
	(scatter busw_rawscf_frac_rank2 year if group == 3, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l)) ///
	(scatter busw_iscf_frac year if group == 3, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash)) ///
	(scatter busw_rawscf_frac_rank2 year if group == 4, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l)) ///
	(scatter busw_iscf_frac year if group == 4, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash)) ///
	, ///
	$graphconfig ytitle("Share of Non C-corp Business Wealth (%)") xtitle("") ///
		legend(label(1 "SCF Top 10%")  ///
			   label(2 "SCF Capitalized Top 10%") ///
			   label(3 "SCF Top 1%") ///
			   label(4 "SCF Capitalized Top 1%") ///
			   label(5 "SCF Top 0.1%") ///
			   label(6 "SCF Capitalized Top 0.1%") ///
			   order(1 2 3 4 5 6) row(3) region(lc(white))) ///
		ysc(titlegap(2))  ylab(0(.2)1) ///
		xlab(1988(3)2012)

graph export "$figdir/sz_scf_fig4b_rerank_busw.pdf", replace

*****************************************************
*** c corp biz  with re-ranking
*****************************************************
	twoway (scatter ccorw_rawscf_frac_rank2 year if group == 2, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l)) ///
	(scatter ccorw_iscf_frac year if group == 2, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash)) ///
	(scatter ccorw_rawscf_frac_rank2 year if group == 3, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l)) ///
	(scatter ccorw_iscf_frac year if group == 3, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash)) ///
	(scatter ccorw_rawscf_frac_rank2 year if group == 4, lcolor("dknavy") mcolor("dknavy") msymbol(d) c(l)) ///
	(scatter ccorw_iscf_frac year if group == 4, lcolor("maroon") mcolor("maroon") msymbol(ch) c(l) lpattern(shortdash)) ///
	, ///
	$graphconfig ytitle("Share of C-corp Business Wealth (%)") xtitle("") ///
		legend(label(1 "SCF Top 10%")  ///
			   label(2 "SCF Capitalized Top 10%") ///
			   label(3 "SCF Top 1%") ///
			   label(4 "SCF Capitalized Top 1%") ///
			   label(5 "SCF Top 0.1%") ///
			   label(6 "SCF Capitalized Top 0.1%") ///
			   order(1 2 3 4 5 6) row(3) region(lc(white))) ///
		ysc(titlegap(2))  ylab(0(.2)1) ///
		xlab(1988(3)2012)

graph export "$figdir/sz_scf_fig4b_rerank_ccorw.pdf", replace
